//
//  LYSCommonWKWebBridgeAPI.m
//  LYSCommonWKWebKitDemo
//
//  Created by dx on 2021/6/2.
//  Copyright © 2021 HENAN. All rights reserved.
//

#import "LYSCommonWKWebBridgeAPI.h"

@implementation LYSCommonWKWebBridgeAPI

- (void)ly_loadUrl:(NSString *)urlStr
{
    [super ly_loadUrl:urlStr];
    [self ly_addAsynAction:@selector(setNativeCache:) target:self name:@"setNativeCache"];
    [self ly_addAsynAction:@selector(getNativeCache:) target:self name:@"getNativeCache"];
}

- (void)setNativeCache:(LYSBridgeInfo *)info
{
    if ([info.parms isKindOfClass:[NSDictionary class]] && [[info.parms allKeys] containsObject:@"key"] && [[info.parms allKeys] containsObject:@"data"]) {
        [[NSUserDefaults standardUserDefaults] setObject:info.parms[@"data"] forKey:info.parms[@"key"]];
        [self ly_evaluateResponse:@{} success:YES message:@"成功!" bridge:info];
    }
}

- (void)getNativeCache:(LYSBridgeInfo *)info
{
    if ([info.parms isKindOfClass:[NSDictionary class]] && [[info.parms allKeys] containsObject:@"key"]) {
        [self ly_evaluateResponse:@{
            @"data":  [[NSUserDefaults standardUserDefaults] objectForKey:info.parms[@"key"]] ? [[NSUserDefaults standardUserDefaults] objectForKey:info.parms[@"key"]] : @""
        } success:YES message:@"成功!" bridge:info];
    }
}


@end
